﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EFCodeCreater.Module
{
    public class CreateRepository
    {
        public static void Create(DataTable table, TableInfo tableinfo, string repositoryContent, string root)
        {

            repositoryContent = repositoryContent.Replace("_tabledesc_", tableinfo.value).Replace("_name_", tableinfo.name);
            var inputforeach = new StringBuilder();
           
            var index = 0;
            foreach (DataRow dataRow in table.Rows)
            {
                inputforeach.AppendLine("                    " + dataRow[0] + " = " + "a." + dataRow[0] +
                                        (index != table.Rows.Count ? "," : ""));
            }
            repositoryContent = repositoryContent.Replace("_inputforeach_", inputforeach.ToString());
            Tool.SaveFile(root + $@"\Infrastructure.Repository\Repository.Sql\{tableinfo.name}Repoistory.cs", repositoryContent);
        }
    }
}
